package com.dmooo.ymx.fragments;

import android.Manifest;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.dmooo.ymx.R;
import com.dmooo.ymx.activity.BaoYouActivity;
import com.dmooo.ymx.activity.CommissionPhbActivity;
import com.dmooo.ymx.activity.DailyBonusActivity;
import com.dmooo.ymx.activity.DialogActivity;
import com.dmooo.ymx.activity.DialogActivity2;
import com.dmooo.ymx.activity.DouActivity;
import com.dmooo.ymx.activity.ElemeActivity;
import com.dmooo.ymx.activity.GaoyongActivity;
import com.dmooo.ymx.activity.GuoyedanActivity;
import com.dmooo.ymx.activity.JdActivity;
import com.dmooo.ymx.activity.JiayoulistActivity;
import com.dmooo.ymx.activity.NewClassActivity;
import com.dmooo.ymx.activity.NewsActivity;
import com.dmooo.ymx.activity.PHBActivity;
import com.dmooo.ymx.activity.PddActivity;
import com.dmooo.ymx.activity.PromotionDetailsActivity;
import com.dmooo.ymx.activity.QdActivity;
import com.dmooo.ymx.activity.SearchActivity;
import com.dmooo.ymx.activity.SearchResultActivity;
import com.dmooo.ymx.activity.TianMaoShuangShiyiActivity;
import com.dmooo.ymx.activity.WebViewActivity;
import com.dmooo.ymx.activity.WebViewActivity2;
import com.dmooo.ymx.activity.WebViewActivity3;
import com.dmooo.ymx.activity.WphActivity;
import com.dmooo.ymx.activity.XuanpinkActivity;
import com.dmooo.ymx.activity.ZeroBuyActivity;
import com.dmooo.ymx.activity.ZhouZhouLeActivity;
import com.dmooo.ymx.adapter.HomeIconAdapter;
import com.dmooo.ymx.adapter.TbActivityAdapter;
import com.dmooo.ymx.adapter.TodayHighlightsAdapter;
import com.dmooo.ymx.base.BaseLazyFragment;
import com.dmooo.ymx.bean.BannerBean;
import com.dmooo.ymx.bean.HaoDanBean;
import com.dmooo.ymx.bean.MessageCenterBean;
import com.dmooo.ymx.bean.MessageEvent;
import com.dmooo.ymx.bean.PDDBean;
import com.dmooo.ymx.bean.PddClient;
import com.dmooo.ymx.bean.PromotionDetailsBean;
import com.dmooo.ymx.bean.Response;
import com.dmooo.ymx.bean.SetBean;
import com.dmooo.ymx.bean.TaobaoGuestBean;
import com.dmooo.ymx.bean.TodayHighlightsBean2;
import com.dmooo.ymx.common.SPUtils;
import com.dmooo.ymx.common.T;
import com.dmooo.ymx.config.Constants;
import com.dmooo.ymx.https.HttpUtils;
import com.dmooo.ymx.https.onOKJsonHttpResponseHandler;
import com.dmooo.ymx.login.WelActivity;
import com.dmooo.ymx.mall.MallGoodsDetailsActivity;
import com.dmooo.ymx.mall.ShopMallActivity;
import com.dmooo.ymx.mall.ShopMallActivty;
import com.dmooo.ymx.malladapter.ShopMallGridAdapter;
import com.dmooo.ymx.mallbean.MallCatbean;
import com.dmooo.ymx.mallbean.ShopMallGoodsBean;
import com.dmooo.ymx.merchantactivity.MerchanthomeActivity;
import com.dmooo.ymx.merchantbean.MerchantGroupbean;
import com.dmooo.ymx.suning.SuningHomeActivity;
import com.dmooo.ymx.utils.CornerTransform;
import com.dmooo.ymx.utils.MyRecyclerView2;
import com.dmooo.ymx.utils.ScrollBanner;
import com.dmooo.ymx.utils.UIUtils;
import com.dmooo.ymx.widget.NoScrollGridView;
import com.gcssloop.widget.PagerGridLayoutManager;
import com.gcssloop.widget.PagerGridSnapHelper;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jd.open.api.sdk.DefaultJdClient;
import com.jd.open.api.sdk.JdClient;
import com.jd.open.api.sdk.JdException;
import com.king.zxing.Intents;
import com.lljjcoder.style.citylist.Toast.ToastUtils;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;
import com.mylhyl.acp.Acp;
import com.mylhyl.acp.AcpListener;
import com.mylhyl.acp.AcpOptions;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.uuch.adlibrary.AdConstant;
import com.uuch.adlibrary.AdManager;
import com.uuch.adlibrary.bean.AdInfo;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;
import com.youth.banner.transformer.ZoomOutTranformer;
import com.zhouwei.mzbanner.MZBannerView;
import com.zhouwei.mzbanner.holder.MZHolderCreator;
import com.zhouwei.mzbanner.holder.MZViewHolder;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.wrapper.HeaderAndFooterWrapper;

import org.apache.commons.lang3.StringUtils;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import cz.msebera.android.httpclient.Header;
import jd.union.open.goods.query.request.GoodsReq;
import jd.union.open.goods.query.request.UnionOpenGoodsQueryRequest;
import jd.union.open.goods.query.response.UnionOpenGoodsQueryResponse;

/**
 * 首页
 * Created by yohn on 2018/7/11.
 */

public class HomeFirstFragment extends BaseLazyFragment implements View.OnClickListener {
    private View view;
    public static HomeFirstFragment fragment;
    private ImageView homeBg;
    //导航标题
    @BindView(R.id.home_recyclerView)
    RecyclerView homeRecyclerView;
    Unbinder unbinder;
    @BindView(R.id.refresh_layout)
    SmartRefreshLayout refreshLayout;

    @BindView(R.id.right_icon)
    ImageView right_icon;
    private String min_id = "1";
    private String pid="39";

    private List<TodayHighlightsBean2> todayHighlightsBeans = new ArrayList<>();
    private TodayHighlightsAdapter highlightsAdapter;
    private MyRecyclerView2 homeGrid;
    private int Home_Search = 0; //0为首页,1为搜索页

    private String search_content;//搜索内容

    private String search_sort;//排序字段

    private boolean has_coupon = true;//是否优惠券

    private int indexNum = 1;

    private int refreshStatus = 0;

    List<HaoDanBean> taobaoGuesChildtBeans = new ArrayList<>();
    List<ShopMallGoodsBean> shopGuesChildtBeans = new ArrayList<>();
    private LinearLayoutManager linearLayoutManager;
    private HeaderAndFooterWrapper headerAndFooterWrapper;
    private RecyclerView recyclerViewAc;
    //wmm
    private Banner banner;
    private MZBannerView banner2;
    private ScrollBanner scrollBanner;
    private List<BannerBean> images3 = new ArrayList<>();
    private List<BannerBean> images = new ArrayList<>();
    private List<MessageCenterBean.MessageCenterChildBean> images2 = new ArrayList<>();
    private HomeIconAdapter homeIconAdapter;
    private List<SetBean.Item> homeItems = new ArrayList<>();
    private RadioGroup page_rg;
    private List<BannerBean> acBanner = new ArrayList<>();
    private TbActivityAdapter tbActivityAdapter;
    View homeTabView;
    //    private RecyclerView tuijianRecy, baoyouRecy, qgRecy;
    List<TaobaoGuestBean.TaobaoGuesChildtBean> nineList = new ArrayList<>();
    //    private NineAdapter nineAdapter;
//    private PHBAdapter phbAdapter;
    DecimalFormat df = new DecimalFormat("0.00");
//    private List<HaoDanBean> list = new ArrayList<>();
//    private List<HaoDanBean> qgList = new ArrayList<>();
//    private TextView txtHour, tipTwo, tipThree;
//    private HomeQGAdapter homeQGAdapter;
    ImageView img1,img2,img3,img4,img5,img6;
    public static HomeFirstFragment getInstance() {
        if (fragment == null) {
            fragment = new HomeFirstFragment();
        }
        return fragment;
    }

    List<MallCatbean> subListByParentChildBeans = new ArrayList<>();

    private ShopMallGridAdapter shopGridAdapter;
    private NoScrollGridView gridView;

    private boolean hasdata = true;
    private Gson gson = new Gson();
    private List<MerchantGroupbean> iconlist = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_first_home, container, false);
        ButterKnife.bind(this, view);
        init();
        addListener();
        isVisible = true;
        lazyload();
        return view;
    }

    private void init() {
        highlightsAdapter = new TodayHighlightsAdapter(getActivity(), R.layout.today_highlights_item, todayHighlightsBeans);
        linearLayoutManager = new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        homeRecyclerView.setLayoutManager(linearLayoutManager);
        //如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
        homeRecyclerView.setHasFixedSize(true);
        homeRecyclerView.setItemAnimator(new DefaultItemAnimator());
        //显示回滚
        homeRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                //屏幕高度
                int screenMeasuredHeight = UIUtils.getScreenMeasuredHeight(getActivity());
                //如果滚动距离大于屏幕高度，那么显示回滚，否则。。。
                if (getScollYDistance() >= (screenMeasuredHeight / 2)) {
                    right_icon.setVisibility(View.VISIBLE);
                } else {
                    right_icon.setVisibility(View.GONE);
                }
                Log.d("TAG", "高度为:" + getScollYDistance());

            }
        });

        //设置一个头部
        homeTabView = getLayoutInflater().inflate(R.layout.home_tab_layout, null);
//        if("N".equals(SPUtils.getStringData(context,"is_tm_11","N"))){
//        }else{
        recyclerViewAc = homeTabView.findViewById(R.id.ac_recy);
        recyclerViewAc.setLayoutManager(new GridLayoutManager(context, 2));
        tbActivityAdapter = new TbActivityAdapter(R.layout.item_tb_ac, acBanner);
        recyclerViewAc.setAdapter(tbActivityAdapter);
        tbActivityAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Bundle bundle = new Bundle();
                bundle.putString("title", acBanner.get(position).taobao_activity_name);
                bundle.putString("material_id", acBanner.get(position).tb_activity_id);
                openActivity(TianMaoShuangShiyiActivity.class, bundle);
            }
        });

        getTbActivity();
        geticon();
//        }
        banner = homeTabView.findViewById(R.id.main_banner);
//        banner.setLayoutParams(new RelativeLayout.LayoutParams(BitmapUtils.getScreenWith(context), (int) (BitmapUtils.getScreenWith(context) / 2.3)));
        banner.setImageLoader(new ImageLoader() {
            @Override
            public void displayImage(Context context, Object path, ImageView imageView) {
                if (context != null && !((Activity) context).isDestroyed())
                    Glide.with(context).load(path).asBitmap().skipMemoryCache(false).dontAnimate().error(R.drawable.no_banner).transform(new CornerTransform(context, 10)).into(imageView);
            }

        });
//        banner.isAutoPlay(true);
        banner2 = homeTabView.findViewById(R.id.home_ad);
        homeBg = homeTabView.findViewById(R.id.home_bg);
        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        banner.setIndicatorGravity(BannerConfig.RIGHT);
        scrollBanner = homeTabView.findViewById(R.id.main_scroll);
        RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        homeTabView.setLayoutParams(layoutParams);
        //优惠转
        homeTabView.findViewById(R.id.ll_home_one).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home_two).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home).setOnClickListener(this);
        homeTabView.findViewById(R.id.img_pinpai).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openActivity(PinPaiFragment.class);
            }
        });
        homeTabView.findViewById(R.id.img_sh).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent4 = new Intent(getActivity(), GaoyongActivity.class);
                intent4.putExtra("url", "/app.php?c=Zhetaoke&a=getBaodanGoods");
                intent4.putExtra("title", "捡漏神单");
                intent4.putExtra("type", "2");
                startActivity(intent4);
            }
        });
        homeTabView.findViewById(R.id.img_sh2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), BaoYouActivity.class);
                intent.putExtra("type", "5");
                startActivity(intent);
            }
        });
        homeTabView.findViewById(R.id.ll_home_three).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home_four).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home_five).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home_six).setOnClickListener(this);
        img1=homeTabView.findViewById(R.id.ll_home_six);
        img2=homeTabView.findViewById(R.id.ll_home_two);
        img3=homeTabView.findViewById(R.id.ll_home_seven);
        img4=homeTabView.findViewById(R.id.img_pinpai);
        img5=homeTabView.findViewById(R.id.img_sh2);
        img6=homeTabView.findViewById(R.id.img_sh);

        homeTabView.findViewById(R.id.ll_home_seven).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home_eight).setOnClickListener(this);
//        homeTabView.findViewById(R.id.txt_cj).setOnClickListener(this);
        homeGrid = homeTabView.findViewById(R.id.home_grid);
        // 1.水平分页布局管理器
        PagerGridLayoutManager layoutManager = new PagerGridLayoutManager(
                2, 5, PagerGridLayoutManager.HORIZONTAL);
        layoutManager.setPageListener(new PagerGridLayoutManager.PageListener() {
            @Override
            public void onPageSizeChanged(int pageSize) {
            }

            @Override
            public void onPageSelect(int pageIndex) {
                page_rg.check(pageIndex);
            }
        });
        page_rg = homeTabView.findViewById(R.id.page_rg);
        layoutManager.setChangeSelectInScrolling(true);
        homeGrid.setLayoutManager(layoutManager);
// 2.设置滚动辅助工具
        PagerGridSnapHelper pageSnapHelper = new PagerGridSnapHelper();
        pageSnapHelper.attachToRecyclerView(homeGrid);
//        homeGrid.setLayoutManager(new GridLayoutManager(context, 5));
        homeIconAdapter = new HomeIconAdapter(context, R.layout.dd, iconlist);
        homeGrid.setAdapter(homeIconAdapter);
//        gridView = new NoScrollGridView(getActivity());
//        gridView.setNumColumns(4);
//        gridView.setGravity(Gravity.CENTER);
//        gridView.setBackgroundColor(context.getResources().getColor(R.color.white));

//        shopGridAdapter = new ShopMallGridAdapter(getActivity(), R.layout.service_home_grid_item, subListByParentChildBeans);
//        gridView.setAdapter(shopGridAdapter);
//        homeGrid.addView(gridView);
        homeIconAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                Bundle bundle=new Bundle();
                bundle.putString("name",iconlist.get(position).cat_name);
                bundle.putString("pid",iconlist.get(position).cat_id);
                openActivity(ShopMallActivty.class,bundle);

//                Intent intent;
//                switch (homeItems.get(position).id) {
//                    case "1":
//                        intent = new Intent(getActivity(), BaoYouActivity.class);
//                        intent.putExtra("type", "20");
//                        startActivity(intent);
//                        break;
//                    case "2":
//                        intent = new Intent(getActivity(), BaoYouActivity.class);
//                        intent.putExtra("type", "9");
//                        startActivity(intent);
//                        break;
//                    case "3":
//                        intent = new Intent(getActivity(), BaoYouActivity.class);
//                        intent.putExtra("type", "2");
//                        startActivity(intent);
//                        break;
//                    case "4":
//                        intent = new Intent(getActivity(), BaoYouActivity.class);
//                        intent.putExtra("type", "5");
//                        startActivity(intent);
//                        break;
//                    case "5":
//                        intent = new Intent(getActivity(), BaoYouActivity.class);
//                        intent.putExtra("type", "4");
//                        startActivity(intent);
//                        break;
//                    case "6":
//                        intent = new Intent(context, WebViewActivity3.class);
//                        intent.putExtra("title", "天猫超市");
//                        intent.putExtra("url", "https://chaoshi.tmall.com/?targetPage=index");
//                        startActivity(intent);
//                        break;
//                    case "7":
//                        intent = new Intent(getActivity(), BaoYouActivity.class);
//                        intent.putExtra("type", "1");
//                        startActivity(intent);
//                        break;
//                    case "8":
//                        openActivity(PHBActivity.class);
//                        break;
//                    case "9":
//                        intent = new Intent(getActivity(), BaoYouActivity.class);
//                        intent.putExtra("type", "22");
//                        startActivity(intent);
//                        break;
//                    case "10":
//                        openActivity(PddActivity.class);
//                        break;
//                    case "11":
//                        openActivity(JdActivity.class);
//                        break;
//                    case "12":
//                        openActivity( ShopMallActivity.class);
//                        break;
//                    case "13":
//                        openActivity(NewClassActivity.class);
//                        break;
//                    case "14":
//                        intent = new Intent(context, WebViewActivity.class);
//                        intent.putExtra("title", "拉新活动");
//                        intent.putExtra("url", Constants.APP_IP + "/wap.php/Rookie/index/uid/" + SPUtils.getStringData(context, Constants.UID, ""));
//                        startActivity(intent);
//                        break;
//                    case "15":
//                        openActivity(ZeroBuyActivity.class);
//                        break;
//                    case "16":
//                        hongbao();
//                        break;
//                    case "17":
//                        openActivity(DailyBonusActivity.class);
//                        break;
//                    case "29":
//                        openActivity(WphActivity.class);
//                        break;
//                    case "19":
//                        intent = new Intent(getActivity(), BaoYouActivity.class);
//                        intent.putExtra("type", "23");
//                        startActivity(intent);
//                        break;
//                    case "20":
//                        intent = new Intent(context, WebViewActivity3.class);
//                        intent.putExtra("title", "天猫国际");
//                        intent.putExtra("url", "https://pages.tmall.com/wow/jinkou/act/zhiyingchaoshi?from=zebra:offline");
//                        startActivity(intent);
//                        break;
//                    case "21":
//                        openActivity(PinPaiFragment.class);
//                        break;
//                    case "22":
//                        intent = new Intent(context, WebViewActivity3.class);
//                        intent.putExtra("title", "生活券");
//                        intent.putExtra("url", "http://www.quanmama.com/t/couponExport/couponList.aspx?categoryid=5475");
//                        startActivity(intent);
//                        break;
//                    case "23":
//                        intent = new Intent(context, DailyBonusActivity.class);
//                        startActivity(intent);
//                        break;
//                    case "24":
//                        intent = new Intent(context, CommissionPhbActivity.class);
//                        startActivity(intent);
//                        break;
//                    case "25":
//                        intent = new Intent(context, WebViewActivity3.class);
//                        intent.putExtra("title", "天猫美妆");
//                        intent.putExtra("url", "https://meizhuang.tmall.com");
//                        startActivity(intent);
//                        break;
//                    case "26":
//                        intent = new Intent(context, WebViewActivity3.class);
//                        intent.putExtra("title", "飞猪");
//                        intent.putExtra("url", "https://h5.m.taobao.com/trip/home/index.html");
//                        startActivity(intent);
//                        break;
//                    case "27":
//                        Bundle bundle = new Bundle();
//                        bundle.putString("id", "0");
//                        openActivity(DouActivity.class, bundle);
//                        break;
//                    case "28":
//                        Acp.getInstance(context).request(new AcpOptions.Builder()
//                                .setPermissions(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
//                                .build(), new AcpListener() {
//                            @Override
//                            public void onGranted() {
//                                openActivity(JiayoulistActivity.class);
//                            }
//
//                            @Override
//                            public void onDenied(List<String> permissions) {
//                                showToast("加油站需要您的定位权限");
//                            }
//                        });
//                        break;
//                    case "30":
//                        openActivity(SuningHomeActivity.class);
//                        break;
//                    case "31":
//                        Intent intent1 = new Intent(getActivity(), GuoyedanActivity.class);
//                        startActivity(intent1);
//                        break;
//                    case "32":
//                        Intent intent4 = new Intent(getActivity(), GaoyongActivity.class);
//                        intent4.putExtra("url", "/app.php?c=Zhetaoke&a=getBaodanGoods");
//                        intent4.putExtra("title", "捡漏神单");
//                        intent4.putExtra("type", "2");
//                        startActivity(intent4);
//                        break;
//                    case "33":
//                        openActivity(ElemeActivity.class);
//                        break;
//                    case "34":
//                        Intent intent12 = new Intent(context, WebViewActivity.class);
//                        intent12.putExtra("title", "充值");
//                        intent12.putExtra("url","http://app.yangkeduo.com/deposit.html");
//                        startActivity(intent12);
//                        break;
//                    case "35":
//                        Acp.getInstance(context).request(new AcpOptions.Builder()
//                                .setPermissions(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
//                                .build(), new AcpListener() {
//                            @Override
//                            public void onGranted() {
//                                openActivity(MerchanthomeActivity.class);
//                            }
//
//                            @Override
//                            public void onDenied(List<String> permissions) {
//                                showToast("需要您的定位权限");
//                            }
//                        });
//                        break;
//                    case "36":
//                        if ("".equals(SPUtils.getStringData(context, "token", ""))) {
//                            openActivity(WelActivity.class);
//                            return;
//                        }
//                        intent = new Intent(context, WebViewActivity3.class);
//                        intent.putExtra("title", "美团酒店");
//                        intent.putExtra("url", "https://runion.meituan.com/url?a=1&key=ebf5da1e1cd2073df1e538618fca245c348&url=https://i.meituan.com/awp/h5/hotel/search/search.html?cevent=imt%2Fhomepage%2Fcategory1%2F20&sid=hkx_"+SPUtils.getStringData(context,"uid",""));
//                        startActivity(intent);
//                        break;
//                    case "37":
//                        intent = new Intent(context, WebViewActivity.class);
//                        intent.putExtra("title", "洗车");
//                        intent.putExtra("url", "https://wash.chengniu.com/wash/#/home?systemCode=CPH5&activityChannel=zxyd&orderChannel=59");
//                        startActivity(intent);
//                        break;
//                    case "43":
//                        RequestParams params=new RequestParams();
//                        params.put("share_code","127SIwqxj");
//                        long timeStamp = System.currentTimeMillis();
//                        params.put("user_id",SPUtils.getStringData(context,"uid","1"));
//                        params.put("timestamp",timeStamp);
////        params.put("secretKey","C78266CF1A8848B48ECF96C0BD5EE465");
//                        Map<String,String> map=new HashMap<>();
//                        map.put("shareCode","127SIwqxj");
//                        map.put("userId",SPUtils.getStringData(context,"uid","1"));
//                        map.put("timestamp",timeStamp+"");
////        map.put("secretKey","C78266CF1A8848B48ECF96C0BD5EE465");
//                        params.put("sign",PddClient.getSign4(map,"C78266CF1A8848B48ECF96C0BD5EE465"));
//                        intent = new Intent(context, WebViewActivity.class);
//                        intent.putExtra("title", "肯德基");
//                        intent.putExtra("url", "https://ot.jfshou.cn/api/entrance?"+params.toString());
//                        startActivity(intent);
//                        break;
//                    case "45":
//                        try {
//                            // 以下固定写法
//                            final Intent intent1e = new Intent(Intent.ACTION_VIEW,
//                                    Uri.parse("alipays://platformapi/startapp?appId=20000193"));
//                            intent1e.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
//                                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
//                            startActivity(intent1e);
//                        } catch (Exception e) {
//                            // 防止没有安装的情况
//                            e.printStackTrace();
//                            ToastUtils.showLongToast(context,"请先安装支付宝");
//                        }
//                        break;
//                    default:
//                        if( homeItems.get(position).href!=null&&!"".equals( homeItems.get(position).href)){
//                            intent = new Intent(context, WebViewActivity.class);
//                            intent.putExtra("title", homeItems.get(position).name);
//                            intent.putExtra("url", homeItems.get(position).href);
//                            startActivity(intent);
//                        }
//                        break;
//                }
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
//        getIndexIcon();
        //头部适配器
        headerAndFooterWrapper = new HeaderAndFooterWrapper(highlightsAdapter);
        //添加一个头部
        headerAndFooterWrapper.addHeaderView(homeTabView);
        homeRecyclerView.setAdapter(headerAndFooterWrapper);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                refreshLayout.autoRefresh();
                getBanner();
                getAD();
                getHomeADimg();
            }
        }, 200);
    }


    private void geticon() {
        RequestParams requestParams = new RequestParams();
        HttpUtils.post(Constants.SLEF_MALL_CAT, requestParams, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            }


            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                try {
                    JSONObject object = new JSONObject(responseString);
                    if ("0".equals(object.getString("code"))) {
                        JSONArray array = object.getJSONObject("data").getJSONArray("list");
                        for (int i = 0; i < array.length(); i++) {
                            iconlist.add(new Gson().fromJson(array.getJSONObject(i).toString(), MerchantGroupbean.class));
                        }
                        int count = (iconlist.size() - 1) / 10 + 1;
                        //4-1=3   /10 ==0.3+1  =1.3
                        for (int i = 0; i < count; i++) {
                            RadioButton rb = (RadioButton) LayoutInflater.from(context).inflate(R.layout.item_page_group, null);
                            rb.setId(i);
                            if (i == 0) {
                                rb.setChecked(true);
                            }
                            page_rg.addView(rb);
                        }


                        homeIconAdapter.notifyDataSetChanged();
                    } else {
                        showToast(object.getString("msg"));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }


    class BannerViewHolder implements MZViewHolder<String> {
        private ImageView mImageView;

        @Override
        public View createView(Context context) {
            View view = LayoutInflater.from(context).inflate(R.layout.img_t, null);
            mImageView = view.findViewById(R.id.img);
            return view;
        }

        @Override
        public void onBind(Context context, int position, final String data) {
            Glide.with(context).load(data).into(mImageView);
        }
    }

    private void getTbActivity() {
        RequestParams requestParams = new RequestParams();
        HttpUtils.post(Constants.TBACTIVITY, requestParams, new onOKJsonHttpResponseHandler<BannerBean>(new TypeToken<Response<BannerBean>>() {
        }) {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//                showToast(throwable.getMessage());
            }

            @Override
            public void onSuccess(int statusCode, Response<BannerBean> datas) {
                if (datas.isSuccess()) {
                    acBanner.addAll(datas.getData().getList());
                    if (acBanner.size() <= 0) {
                        homeTabView.findViewById(R.id.ll_tm).setVisibility(View.GONE);
                    }
                    tbActivityAdapter.notifyDataSetChanged();
                } else {
                    showToast(datas.getMsg());
                }
            }
        });
    }

    /**
     * @属性:获取屏幕高度的方法
     * @开发者:陈飞
     * @时间:2018/8/7 14:22
     */
    public long getScollYDistance() {
        int position = linearLayoutManager.findFirstVisibleItemPosition();
        View firstVisiableChildView = linearLayoutManager.findViewByPosition(position);
        int itemHeight = firstVisiableChildView.getHeight();
        return (position) * itemHeight - firstVisiableChildView.getTop();
    }

    private void addListener() {
        RequestParams requestParams = new RequestParams();
        requestParams.put("cat_id", 9);
        HttpUtils.post(Constants.GET_BANNER, requestParams, new onOKJsonHttpResponseHandler<BannerBean>(new TypeToken<Response<BannerBean>>() {
        }) {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//                showToast(throwable.getMessage());
            }

            @Override
            public void onSuccess(int statusCode, Response<BannerBean> datas) {
                if (datas.isSuccess()) {
                    List<BannerBean> bannerBeans=datas.getData().getList();
                    for(int i=0;i<bannerBeans.size();i++){
                        switch (bannerBeans.get(i).getId()){
                            case "95":
//                                Glide.with(context).load(Constants.APP_IP+bannerBeans.get(i).getImg()).into(img1);
                                break;
                            case "96":
//                                Glide.with(context).load(Constants.APP_IP+bannerBeans.get(i).getImg()).into(img2);
                                break;
                            case "97":
                                Glide.with(context).load(Constants.APP_IP+bannerBeans.get(i).getImg()).into(img3);
                                break;
                            case "98":
                                Glide.with(context).load(Constants.APP_IP+bannerBeans.get(i).getImg()).into(img4);
                                break;
                            case "99":
                                Glide.with(context).load(Constants.APP_IP+bannerBeans.get(i).getImg()).into(img5);
                                break;
                            case "100":
                                Glide.with(context).load(Constants.APP_IP+bannerBeans.get(i).getImg()).into(img6);
                                break;

                        }
                    }
                } else {
                }
            }
        });
        scrollBanner.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (images2.size() > 0) {
                    Intent intent = new Intent(context, NewsActivity.class);
                    intent.putExtra("title", images2.get(scrollBanner.getCurrentPosition() == images2.size() - 1 ? 0 : scrollBanner.getCurrentPosition() + 1).getTitle());
                    intent.putExtra("article_id", images2.get(scrollBanner.getCurrentPosition() == images2.size() - 1 ? 0 : scrollBanner.getCurrentPosition() + 1).getArticle_id());
                    startActivity(intent);
                }
            }
        });
        banner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {
                if ("1".equals(images.get(position).getType())) {
                    if ("".equals(images.get(position).getHref())) {
                        return;
                    }
                    if (images.get(position).getHref() != null) {
                        Intent intent = new Intent(context, WebViewActivity.class);
                        intent.putExtra("title", images.get(position).getTitle());
                        intent.putExtra("url", images.get(position).getHref());
                        startActivity(intent);
                    }
                } else if ("2".equals(images.get(position).getType())) {
                    Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.taobao.taobao");
                    if (intent != null) {
                        //获取剪贴板管理器：
                        ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                        // 创建普通字符型ClipData
                        ClipData mClipData = ClipData.newPlainText("Label", images.get(position).getType_value());
                        // 将ClipData内容放到系统剪贴板里。
                        cm.setPrimaryClip(mClipData);
                        startActivity(intent);
                        return;
                    } else {
                        T.showShort(context, "未安装淘宝客户端");
                    }
                } else if ("3".equals(images.get(position).getType())) {
                    Uri uri = Uri.parse(images.get(position).getType());
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                } else if ("4".equals(images.get(position).getType())) {
                    Uri uri = Uri.parse(images.get(position).getType());
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                    return;
                } else if ("6".equals(images.get(position).getType())) {
                    Intent intent = new Intent(context, WebViewActivity2.class);
                    intent.putExtra("title", "年货节");
                    intent.putExtra("url", "");
                    startActivity(intent);
                    return;
                } else if ("7".equals(images.get(position).getType()) || "8".equals(images.get(position).getType())) {
                    hongbao();
                    return;
                } else if ("9".equals(images.get(position).getType())) {
                    Bundle bundle = new Bundle();
                    bundle.putString("num_iid", images.get(position).getType_value());
                    openActivity(PromotionDetailsActivity.class, bundle);
                    return;
                } else if ("10".equals(images.get(position).getType())) {
                    Intent intent = new Intent(context, WebViewActivity.class);
                    intent.putExtra("title", "拉新活动");
                    intent.putExtra("url", Constants.APP_IP + "/wap.php/Rookie/index/uid/" + SPUtils.getStringData(context, Constants.UID, ""));
                    startActivity(intent);
                    return;
                } else if ("11".equals(images.get(position).getType())) {
                    openActivity(ZeroBuyActivity.class);
                    return;
                } else if ("12".equals(images.get(position).getType())) {
                    openActivity(XuanpinkActivity.class);
                    return;
                } else if ("13".equals(images.get(position).getType())) {
                    //进洞
                    openActivity(JdActivity.class);
                    return;
                }else if ("16".equals(images.get(position).getType())) {
                    //进洞
                    openActivity(ElemeActivity.class);
                    return;
                } else if ("14".equals(images.get(position).getType())) {
//                    openActivity(XuanpinkActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("title", images.get(position).getTitle());
                    bundle.putString("material_id", images.get(position).getType_value());
                    openActivity(TianMaoShuangShiyiActivity.class, bundle);
                    return;
                } else if ("15".equals(images.get(position).getType())) {
                    Acp.getInstance(context).request(new AcpOptions.Builder()
                            .setPermissions(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
                            .build(), new AcpListener() {
                        @Override
                        public void onGranted() {
                            openActivity(JiayoulistActivity.class);
                        }

                        @Override
                        public void onDenied(List<String> permissions) {
                            showToast("加油站需要您的定位权限");
                        }
                    });
                    return;
                }
            }
        });
        banner2.setBannerPageClickListener(new MZBannerView.BannerPageClickListener() {
            @Override
            public void onPageClick(View view, int position) {
                Log.d("dfsd",images3.get(position).getType());
                if ("1".equals(images3.get(position).getType())) {
                    if ("".equals(images3.get(position).getHref())) {
                        return;
                    }
                    Intent intent = new Intent(context, WebViewActivity.class);
                    intent.putExtra("title", images3.get(position).getTitle());
                    intent.putExtra("url", images3.get(position).getHref());
                    startActivity(intent);
                } else if ("2".equals(images3.get(position).getType())) {
                    Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.taobao.taobao");
                    if (intent != null) {
                        //获取剪贴板管理器：
                        ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                        // 创建普通字符型ClipData
                        ClipData mClipData = ClipData.newPlainText("Label", images3.get(position).getType_value());
                        // 将ClipData内容放到系统剪贴板里。
                        cm.setPrimaryClip(mClipData);
                        startActivity(intent);
                        return;
                    } else {
                        T.showShort(context, "未安装淘宝客户端");
                    }
                } else if ("3".equals(images3.get(position).getType())) {
                    Uri uri = Uri.parse(images3.get(position).getType());
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                } else if ("4".equals(images3.get(position).getType())) {
                    Uri uri = Uri.parse(images3.get(position).getType());
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                    return;
                } else if ("6".equals(images3.get(position).getType())) {
                    Intent intent = new Intent(context, WebViewActivity2.class);
                    intent.putExtra("title", "年货节");
                    intent.putExtra("url", "");
                    startActivity(intent);
                    return;
                } else if ("7".equals(images3.get(position).getType()) || "8".equals(images3.get(position).getType())) {
                    hongbao();
                    return;
                }else if ("16".equals(images3.get(position).getType())) {
                    //进洞
                    openActivity(ElemeActivity.class);
                    return;
                }  else if ("9".equals(images3.get(position).getType())) {
                    Bundle bundle = new Bundle();
                    bundle.putString("num_iid", images3.get(position).getType_value());
                    openActivity(PromotionDetailsActivity.class, bundle);
                    return;
                } else if ("10".equals(images3.get(position).getType())) {
                    Intent intent = new Intent(context, WebViewActivity.class);
                    intent.putExtra("title", "拉新活动");
                    intent.putExtra("url", Constants.APP_IP + "/wap.php/Rookie/index/uid/" + SPUtils.getStringData(context, Constants.UID, ""));
                    startActivity(intent);
                    return;
                } else if ("11".equals(images3.get(position).getType())) {
                    openActivity(ZeroBuyActivity.class);
                    return;
                } else if ("12".equals(images3.get(position).getType())) {
                    openActivity(XuanpinkActivity.class);
                    return;
                } else if ("17".equals(images3.get(position).getType())) {
//                    openActivity(ZhouZhouLeActivity.class);
                    zhouzhoule();
                    return;
                } else if ("13".equals(images3.get(position).getType())) {
                    //进洞
                    openActivity(JdActivity.class);
                    return;
                } else if ("14".equals(images3.get(position).getType())) {
                    Bundle bundle = new Bundle();
                    bundle.putString("title", images3.get(position).getTitle());
                    bundle.putString("material_id", images3.get(position).getType_value());
                    openActivity(TianMaoShuangShiyiActivity.class, bundle);
                    return;
                } else if ("15".equals(images3.get(position).getType())) {
                    Acp.getInstance(context).request(new AcpOptions.Builder()
                            .setPermissions(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
                            .build(), new AcpListener() {
                        @Override
                        public void onGranted() {
                            openActivity(JiayoulistActivity.class);
                        }

                        @Override
                        public void onDenied(List<String> permissions) {
                            showToast("加油站需要您的定位权限");
                        }
                    });
                    return;
                }
            }
        });

        banner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    if (images.get(position).getColor() == null) {
                        images.get(position).setColor("");
                    }
                    homeBg.getDrawable().setTint(Color.parseColor(images.get(position).getColor()));
                    SPUtils.saveStringData(context, "color", images.get(position).getColor());
                    refreshLayout.setPrimaryColors(Color.parseColor(images.get(position).getColor()), Color.WHITE);
                    MessageEvent event = new MessageEvent(images.get(position).getColor());
                    EventBus.getDefault().post(event);
                    banner.isAutoPlay(true);
                    banner.startAutoPlay();
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        refreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                switch (Home_Search) {
                    case 0:
                        if (hasdata) {
                            refreshStatus = 0;
                            indexNum++;
                            getTbkListRequst(search_sort, "必推精选", "服装");
                        } else {
                            showToast("没有更多数据了");
                            refreshLayout.finishLoadMore();
                        }
                        break;
                    case 1:
                        if (hasdata) {
                            refreshStatus = 0;
                            indexNum++;
                            getTbkListRequst(search_sort, "", search_content);
                        } else {
                            showToast("没有更多数据了");
                            refreshLayout.finishLoadMore();
                        }
                        break;
                }
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                indexNum = 1;
                hasdata = true;
                switch (Home_Search) {
                    case 0: //首页
                        refreshStatus = 1;
                        getTbkListRequst("tk_total_sales_des", "必推精选", "服装");
                        break;
                    case 1: //搜索页
                        refreshStatus = 1;
                        getTbkListRequst(search_sort, "", search_content);
                        break;
                }
            }
        });
        homeRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
//                if (getScollYDistance() > bgHead2.getMeasuredHeight()) {
//                    bgHead2.setVisibility(View.VISIBLE);
//                    bgHead2.getBackground().mutate().setAlpha(255);
//                } else {
//                    if (getScollYDistance() == 0) {
//                        bgHead2.setVisibility(View.INVISIBLE);
//                        return;
//                    }
//                    bgHead2.setVisibility(View.VISIBLE);
//                    bgHead2.getBackground().mutate().setAlpha((int) (getScollYDistance() * 1.00 * 255 / bgHead2.getMeasuredHeight()));
//                }
            }
        });
    }
    private void zhouzhoule() {
        String time = String.valueOf(System.currentTimeMillis() / 1000);
        RequestParams requestParams = new RequestParams();
        requestParams.put("data_type", PddClient.data_type);
        requestParams.put("version", PddClient.version);
        requestParams.put("timestamp", time);
        requestParams.put("token", SPUtils.getStringData(context, "token", ""));
        requestParams.put("type", "yxm.UserBalanceRecord.receiveBonus2");
        Map<String, String> temp = new HashMap<>();
        temp.put("data_type", PddClient.data_type);
        temp.put("version", PddClient.version);
        temp.put("timestamp", time);
        temp.put("token", SPUtils.getStringData(context, "token", ""));
        temp.put("type", "yxm.UserBalanceRecord.receiveBonus2");
        String sign = PddClient.getSign1(temp);
        requestParams.put("sign", sign);
        HttpUtils.post(Constants.HONGBAO2, requestParams, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {

            }

            @Override
            public void onStart() {
                super.onStart();
                showLoadingDialog();
            }

            @Override
            public void onFinish() {
                super.onFinish();
                closeLoadingDialog();
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                try {
                    JSONObject jsonObject = new JSONObject(responseString);
                    int code = jsonObject.optInt("code");
                    String msg = jsonObject.optString("msg");
                    Intent intent = new Intent(context, ZhouZhouLeActivity.class);
                    if (code == 0) {
                        intent.putExtra("money", jsonObject.getString("money"));
                        intent.putExtra("mess", "红包已存至余额~");
                        startActivity(intent);
                    } else {
                        showToast(msg);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }
    private void hongbao() {
        String time = String.valueOf(System.currentTimeMillis() / 1000);
        RequestParams requestParams = new RequestParams();
        requestParams.put("data_type", PddClient.data_type);
        requestParams.put("version", PddClient.version);
        requestParams.put("timestamp", time);
        requestParams.put("token", SPUtils.getStringData(context, "token", ""));
        requestParams.put("type", "hkx.UserBalanceRecord.receiveBonus");
        Map<String, String> temp = new HashMap<>();
        temp.put("data_type", PddClient.data_type);
        temp.put("version", PddClient.version);
        temp.put("timestamp", time);
        temp.put("token", SPUtils.getStringData(context, "token", ""));
        temp.put("type", "hkx.UserBalanceRecord.receiveBonus");
        String sign = PddClient.getSign1(temp);
        requestParams.put("sign", sign);
        HttpUtils.post(Constants.HONGBAO, requestParams, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {

            }

            @Override
            public void onStart() {
                super.onStart();
                showLoadingDialog();
            }

            @Override
            public void onFinish() {
                super.onFinish();
                closeLoadingDialog();
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                try {
                    JSONObject jsonObject = new JSONObject(responseString);
                    int code = jsonObject.optInt("code");
                    String msg = jsonObject.optString("msg");
                    Intent intent = new Intent(context, QdActivity.class);
                    intent.putExtra("money", jsonObject.getString("money"));
                    SPUtils.saveIntData(context, "hongbao", 1);
                    if (code == 0) {
                        intent.putExtra("mess", "新年红包已存至余额~");
                    } else {
                        intent.putExtra("mess", msg);
                    }
                    startActivity(intent);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    protected void lazyload() {
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.right_icon:
                homeRecyclerView.post(new Runnable() {
                    @Override
                    public void run() {
                        homeRecyclerView.smoothScrollToPosition(0);
                    }
                });
                break;
            case R.id.tv_title_content://搜索
                openActivity(SearchActivity.class);
                break;
            case R.id.ll_home_one:
                openActivity(ZeroBuyActivity.class);
                break;
            case R.id.ll_home_seven://过夜单
                Intent intent1 = new Intent(getActivity(), GuoyedanActivity.class);

                startActivity(intent1);
//                intent = new Intent(getActivity(), BaoYouActivity.class);
//                intent.putExtra("type", "6");
//                startActivity(intent);
                break;
            case R.id.ll_home_eight://捡漏神单
                Intent intent4 = new Intent(getActivity(), GaoyongActivity.class);
                intent4.putExtra("url", "/app.php?c=Zhetaoke&a=getBaodanGoods");
                intent4.putExtra("title", "捡漏神单");
                intent4.putExtra("type", "2");
                startActivity(intent4);
//                showToast( "敬请期待!" );
                break;
            case R.id.ll_home_two://本地店铺
                Acp.getInstance(context).request(new AcpOptions.Builder()
                        .setPermissions(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION)
                        .build(), new AcpListener() {
                    @Override
                    public void onGranted() {
                        openActivity(MerchanthomeActivity.class);
                    }

                    @Override
                    public void onDenied(List<String> permissions) {
                        showToast("需要您的定位权限");
                    }
                });
//                openActivity(PHBActivity.class);
                break;
            case R.id.ll_home_three:
                intent = new Intent(getActivity(), BaoYouActivity.class);
                intent.putExtra("type", "4");
                startActivity(intent);
                break;
            case R.id.ll_home_four:
                intent = new Intent(getActivity(), BaoYouActivity.class);
                intent.putExtra("type", "22");
                startActivity(intent);
                break;
            case R.id.ll_home_five:
                intent = new Intent(getActivity(), BaoYouActivity.class);
                intent.putExtra("type", "2");
                startActivity(intent);
                break;
            case R.id.ll_home_six:
                //自营商城
                openActivity( ShopMallActivity.class);
//                intent = new Intent(getActivity(), BaoYouActivity.class);
//                intent.putExtra("type", "1");
//                startActivity(intent);
                break;
            case R.id.ll_home:
//                openActivity();
                break;
        }
    }

    /**
     * @属性:获取子级淘宝商品分类列表
     * @开发者:陈飞
     * @时间:2018/7/26 16:18
     */
    private void getSubListByParentRequst() {
        if (TextUtils.isEmpty(pid)) {
            showToast("没有获取到父类pid");
            return;
        }
        RequestParams requestParams = new RequestParams();
        requestParams.put("pid", pid);
        HttpUtils.post(Constants.SLEF_MALL_CAT_SUB, requestParams, new onOKJsonHttpResponseHandler<MallCatbean>(new TypeToken<Response<MallCatbean>>() {
        }) {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                showToast(responseString);
            }

            @Override
            public void onStart() {
                super.onStart();
            }

            @Override
            public void onFinish() {
                super.onFinish();
            }

            @Override
            public void onSuccess(int statusCode, Response<MallCatbean> datas) {
                if (datas.isSuccess()) {
                    List<MallCatbean> list = datas.getData().list;
                    subListByParentChildBeans.clear();
                    subListByParentChildBeans.addAll(list);
                } else {
                    showToast(datas.getMsg());
                }
                homeIconAdapter.notifyDataSetChanged();
            }
        });
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    @Override
    protected void ReceiverBroadCastMessage(String status, String result, Serializable serializable, Intent intent) {
        super.ReceiverBroadCastMessage(status, result, serializable, intent);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    /**
     * @属性:获取推荐商品列表
     * @开发者:WMM
     * @时间:2018/11/20 17:05
     */
    private synchronized void getTbkListRequst(String sort, final String title, String search) {
        RequestParams requestParams = new RequestParams();
        requestParams.put("type", "1");
        requestParams.put("cid", "0");
        requestParams.put("min_id", min_id);
        HttpUtils.post(Constants.GET_NINEBY_NEW_HD, requestParams, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                showToast(throwable.getMessage());
            }

            @Override
            public void onStart() {
                super.onStart();
            }

            @Override
            public void onFinish() {
                super.onFinish();
                if (refreshLayout != null) {
                    refreshLayout.finishRefresh();
                    refreshLayout.finishLoadMore();
                }
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                try {
                    JSONObject object = new JSONObject(responseString);
                    if ("1".equals(object.getString("code"))) {
                        JSONArray array = object.getJSONArray("data");
                        if (min_id.equals("1")) {
                            taobaoGuesChildtBeans.clear();
                        }
                        todayHighlightsBeans.clear();
                        min_id = object.getString("min_id");
                        if (array.length() <= 0) {
                            hasdata = false;
                            return;
                        }
                        for (int i = 0; i < array.length(); i++) {
                            taobaoGuesChildtBeans.add(new Gson().fromJson(array.getJSONObject(i).toString(), HaoDanBean.class));
                        }
                        TodayHighlightsBean2 todayHighlightsBean = new TodayHighlightsBean2();
                        todayHighlightsBean.setTitle(title);
                        todayHighlightsBean.setList(taobaoGuesChildtBeans);
                        todayHighlightsBeans.add(todayHighlightsBean);
                        headerAndFooterWrapper.notifyDataSetChanged();
                        if (array.length() <= 0) {
                            hasdata = false;
                        }
                    } else {
                        showToast(object.getString("msg"));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        });
    }

    private void getHomeADimg() {
        RequestParams requestParams = new RequestParams();
        requestParams.put("cat_id", 3);
        HttpUtils.post(Constants.GET_BANNER, requestParams, new onOKJsonHttpResponseHandler<BannerBean>(new TypeToken<Response<BannerBean>>() {
        }) {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//                showToast(throwable.getMessage());
            }

            @Override
            public void onSuccess(int statusCode, Response<BannerBean> datas) {
                if (datas.isSuccess()) {
                    images3.clear();
                    images3.addAll(datas.getData().getList());
                    List<String> strings = new ArrayList<>();
                    for (int i = 0; i < images3.size(); i++) {
                        strings.add(Constants.APP_IP + images3.get(i).getImg());
                    }
                    if (images3.size() <= 0) {
                        banner2.setVisibility(View.GONE);
                    } else {
                        banner2.setVisibility(View.VISIBLE);
                        banner2.setPages(strings, new MZHolderCreator<BannerViewHolder>() {
                            @Override
                            public BannerViewHolder createViewHolder() {
                                return new BannerViewHolder();
                            }
                        });
                        banner2.start();
                    }
                } else {
                    showToast(datas.getMsg());
                }
            }
        });
    }

    private void getAD() {
        RequestParams requestParams = new RequestParams();
        requestParams.put("cat_id", 4);
        HttpUtils.post(Constants.MESSAGE_ARTICLE_GETARTICLELIST_URL, requestParams, new onOKJsonHttpResponseHandler<MessageCenterBean>(new TypeToken<Response<MessageCenterBean>>() {
        }) {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//                showToast(throwable.getMessage());
            }

            @Override
            public void onSuccess(int statusCode, Response<MessageCenterBean> datas) {
                if (datas.isSuccess()) {
                    if (datas.getData().getList().size() <= 0) {
                        return;
                    }
                    images2.clear();
                    images2.addAll(datas.getData().getList());
                    List<String> strings = new ArrayList<>();
                    for (int i = 0; i < images2.size(); i++) {
                        strings.add(images2.get(i).getTitle());
                    }
                    if (images2.size() > 0)
                        strings.add(images2.get(0).getTitle());
                    scrollBanner.setList(strings);
                    scrollBanner.startScroll();
                } else {
                    showToast(datas.getMsg());
                }
            }
        });
    }

    private void tankuang() {
        final AdInfo adInfo = new AdInfo();
        List<AdInfo> adInfos = new ArrayList<>();
        final AdManager adManager = new AdManager(getActivity(), adInfos);
        adInfo.setActivityImg(Constants.APP_IP + "/Public/static/images/chunjie.png");
        adInfo.setUrl("");
        adInfo.setTitle("");
        adInfos.add(adInfo);
        adManager.setOnImageClickListener(new AdManager.OnImageClickListener() {
            @Override
            public void onImageClick(View view, AdInfo advInfo) {
                hongbao();
                adManager.dismissAdDialog();
            }
        }).setOnCloseClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        adManager.setOverScreen(true)
                .setPageTransformer(new ZoomOutTranformer()).showAdDialog(AdConstant.ANIM_UP_TO_DOWN);
    }

    private void getIndexIcon() {
        RequestParams requestParams = new RequestParams();
        HttpUtils.post(Constants.SET, requestParams, new onOKJsonHttpResponseHandler<SetBean>(new TypeToken<Response<SetBean>>() {
        }) {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//                showToast(throwable.getMessage());
            }

            @Override
            public void onSuccess(int statusCode, Response<SetBean> datas) {
                if (datas.isSuccess()) {
                    for (int i = 0; i < datas.getData().moduleList.size(); i++) {
                        if ("Y".equals(datas.getData().moduleList.get(i).is_index_show)) {
                            homeItems.add(datas.getData().moduleList.get(i));
                        }
                    }
                    int count = (homeItems.size() - 1) / 10 + 1;
                    for (int i = 0; i < count; i++) {
                        RadioButton rb = (RadioButton) LayoutInflater.from(context).inflate(R.layout.item_page_group, null);
                        rb.setId(i);
                        if (i == 0) {
                            rb.setChecked(true);
                        }
                        page_rg.addView(rb);
                    }
                    homeIconAdapter.notifyDataSetChanged();
                } else {
                    showToast(datas.getMsg());
                }
            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == getActivity().RESULT_OK && requestCode == 5) {
            String temp = data.getStringExtra(Intents.Scan.RESULT);
            if (!"".equals(temp)) {
                if (temp.contains("mobile.yangkeduo.com")) {
                    Uri uri = Uri.parse(temp);
                    if (uri.getQueryParameter("goods_id") != null && !"".equals(uri.getQueryParameter("goods_id"))) {
                        getPddDetail(uri.getQueryParameter("goods_id"));
                    }
                } else if (temp.contains("item.m.jd.com/product")) {
                    getJdGoodsRequest(StringUtils.substringBetween(temp, "product/", ".html"));
                } else {
                    getGoodsMsgRequest(temp);
                }
            }
        }
    }

    /**
     * @属性:获取拼多多商品详情
     * @开发者:wmm
     * @时间:2018/11/22 9:00
     */
    private void getPddDetail(final String goods_id) {
        RequestParams requestParams = new RequestParams();
        requestParams.put("goods_id", goods_id);
        HttpUtils.post(Constants.GET_PDD_DETAIL, requestParams, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                showToast(responseString);
            }

            @Override
            public void onFinish() {
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                try {
                    if (new JSONObject(responseString).getInt("code") != 0) {
                        T.showShort(context, "该商品没有优惠券或奖");
                        return;
                    }
                    DecimalFormat df = new DecimalFormat("0.00");
                    JSONObject object = new JSONObject(responseString).getJSONObject("data").getJSONObject("goods_details");
                    Intent intent = new Intent(context, DialogActivity.class);
                    Gson gson = new Gson();
                    double tem = (Double.valueOf(object.getString("min_group_price")) - Double.valueOf(object.getString("coupon_discount"))) * Double.valueOf(df.format(Double.valueOf(object.getString("promotion_rate")) / 1000));
                    object.put("commission", df.format(tem * SPUtils.getIntData(context, "rate", 0) / 100));
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("goods", gson.fromJson(object.toString().replace("goods_gallery_urls", "imagss"), PDDBean.class));
                    intent.putExtra("goods", bundle);
                    intent.putExtra("pic", object.getString("goods_thumbnail_url"));
                    intent.putExtra("title", object.getString("goods_name"));
                    intent.putExtra("commission", "");
                    intent.putExtra("type", "pdd");
                    startActivity(intent);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * @属性:获取京东推送商品详情
     * @开发者:wmm
     * @时间:2018/12/11 9:50
     */
    private Handler handlers = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            T.showShort(context, "该商品没有优惠券或奖");
            super.handleMessage(msg);
        }
    };

    private void getJdGoodsRequest(String id) {
//        JAnalyticsInterface.onEvent(this,new CountEvent("jd_copy_search_lq"));
        String SERVER_URL = "https://router.jd.com/api";
        String appKey = "fc4944df63b0cbbc8d8e28dbee6de305";
        String appSecret = "73f69b7a049642cdb8e8f35081069769";
        String accessToken = "";
        final JdClient client = new DefaultJdClient(SERVER_URL, accessToken, appKey, appSecret);
        final UnionOpenGoodsQueryRequest request = new UnionOpenGoodsQueryRequest();
        final GoodsReq goodsReq = new GoodsReq();
        goodsReq.setSkuIds(new Long[]{Long.valueOf(id)});
        goodsReq.setPageSize(6);
        goodsReq.setPageIndex(1);
        request.setGoodsReqDTO(goodsReq);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    UnionOpenGoodsQueryResponse response = client.execute(request);
                    if (response.getData() == null) {
                        handlers.sendEmptyMessage(0);
                        return;
                    }
                    if (response.getData().length <= 0) {
                        handlers.sendEmptyMessage(0);
                        return;
                    }
                    try {
                        Intent intent = new Intent(context, DialogActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("goods", response.getData()[0]);
                        intent.putExtra("goods", bundle);
                        intent.putExtra("pic", response.getData()[0].getImageInfo()[0].getImageList()[0].getUrl());
                        intent.putExtra("title", response.getData()[0].getSkuName());
                        intent.putExtra("commission", "");
                        intent.putExtra("type", "jd");
                        startActivity(intent);
                    } catch (Exception e) {
                        Log.d("jddddj", "3" + e.toString());

                    }
                } catch (JdException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    private void getGoodsMsgRequest(final String tkl) {
        String url = "";
        RequestParams requestParams = new RequestParams();
        requestParams.put("tkl", tkl);
        HttpUtils.post(Constants.SEARCHTKL, requestParams, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            }

            @Override
            public void onFinish() {
                super.onFinish();
                closeLoadingDialog();
            }

            @Override
            public void onStart() {
                super.onStart();
                showLoadingDialog();
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                try {
                    JSONObject object = new JSONObject(responseString);
                    if (object.getInt("code") == 0) {
                        object = object.getJSONObject("data");
                        Intent intent = new Intent(context, DialogActivity.class);
                        intent.putExtra("url", tkl);
                        intent.putExtra("num_iid", object.getString("num_iid"));
                        intent.putExtra("commission", "");
                        intent.putExtra("type", "tb");
//                        startActivity(intent);
                        getDetail(object.getString("num_iid"), intent);
                    } else {
                        if (tkl.startsWith("【") && tkl.contains("http") && tkl.contains("￥")) {
                            //获取剪贴板管理器：
                            Bundle bundle = new Bundle();
                            bundle.putString("content", tkl.substring(tkl.indexOf("【") + 1, tkl.lastIndexOf("】")));
                            bundle.putInt("type", 0);//1高级搜索 0 普通搜索
                            openActivity(SearchResultActivity.class, bundle);
                            showToast(object.getString("msg"));
                        } else {
                            Intent intent = new Intent(context, DialogActivity2.class);
                            intent.putExtra("search", tkl);
                            startActivity(intent);
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private void getDetail(String num_iid, final Intent intent) {
        RequestParams requestParams = new RequestParams();
        requestParams.put("num_iid", num_iid);
        HttpUtils.post(Constants.HOME_TBK_GETGOODSMSG_URL, requestParams, new onOKJsonHttpResponseHandler<PromotionDetailsBean>(new TypeToken<Response<PromotionDetailsBean>>() {
        }) {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                showToast(responseString);
            }

            @Override
            public void onFinish() {
                super.onFinish();
                closeLoadingDialog();
            }

            @Override
            public void onStart() {
                super.onStart();
                showLoadingDialog();
            }

            @Override
            public void onSuccess(int statusCode, Response<PromotionDetailsBean> datas) {
                if (datas.isSuccess()) {
                    PromotionDetailsBean data = datas.getData();
                    if (data != null) {
                        intent.putExtra("pic", data.getPict_url());
                        intent.putExtra("title", data.getTitle());
                        intent.putExtra("one", data.getCommission());
                        intent.putExtra("two", data.getZk_final_price());
                        intent.putExtra("three", data.getCoupon_amount());
                        startActivity(intent);
                    }
                } else {
                    showToast(datas.getMsg());
                }
            }
        });
    }

    private void getBanner() {
        RequestParams requestParams = new RequestParams();
        requestParams.put("cat_id", 1);
        HttpUtils.post(Constants.GET_BANNER, requestParams, new onOKJsonHttpResponseHandler<BannerBean>(new TypeToken<Response<BannerBean>>() {
        }) {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//                showToast(throwable.getMessage());
            }

            @Override
            public void onSuccess(int statusCode, Response<BannerBean> datas) {
                if (datas.isSuccess()) {
                    images.clear();
                    images.addAll(datas.getData().getList());
                    List<String> strings = new ArrayList<>();
                    for (int i = 0; i < images.size(); i++) {
                        strings.add(Constants.APP_IP + images.get(i).getImg());
                        if ("15".equals(images.get(i).getId()) && SPUtils.getIntData(context, "hongbao", 0) != 1) {
                            //有红包，并且没领过
//                            tankuang();
                        }
                    }
//                    if (images.get(position).getColor() == null) {
//                        images.get(position).setColor("");
//                    }
//                    homeBg.getDrawable().setTint(Color.parseColor(images.get(position).getColor()));
//                    SPUtils.saveStringData(context, "color", images.get(position).getColor());
//                    refreshLayout.setPrimaryColors(Color.parseColor(images.get(position).getColor()), Color.WHITE);
//                    MessageEvent event = new MessageEvent(images.get(position).getColor());
//                    EventBus.getDefault().post(event);


                    banner.startAutoPlay();
                    banner.isAutoPlay(true);
                    banner.setDelayTime(5000);
                    banner.startAutoPlay();
//                    banner.update(strings);
                } else {
                    showToast(datas.getMsg());
                }
            }
        });
    }
}
